package org.afun.oldhand.order.fragment;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import org.afun.oldhand.R;
import org.afun.oldhand.base.BaseFragment;
import org.afun.oldhand.order.adapter.OrderItemAdapter;
import org.afun.oldhand.order.javaBean.ItemBean;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link Order0Fragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class Order0Fragment extends BaseFragment {
    private View view;
    private List<ItemBean> data = new ArrayList<>();

    public Order0Fragment() {
        // Required empty public constructor
    }

    public static Order0Fragment newInstance() {
        Order0Fragment fragment = new Order0Fragment();
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return initView();
    }

    @Override
    public View initView() {
        if (view == null) {
            view = View.inflate(mContext,R.layout.fragment_order0,null);
        }
//        Log.e("test", "initView--order...");

        RecyclerView recyclerView = view.findViewById(R.id.ov);
        data.add(new ItemBean(null, "xxx教练1", "2021-11-17",
                "已完成", "陪练一个半小时", "￥150"));
        data.add(new ItemBean(null, "xxx教练2", "2021-11-17",
                "已完成", "陪练一个半小时", "￥150"));
        data.add(new ItemBean(null, "xxx教练3", "2021-11-17",
                "已完成", "陪练一个半小时", "￥150"));
        data.add(new ItemBean(null, "xxx教练4", "2021-11-17",
                "已完成", "陪练一个半小时", "￥150"));
        // 设置线性布局
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this.mContext);
        recyclerView.setLayoutManager(linearLayoutManager);

        OrderItemAdapter orderItemAdapter = new OrderItemAdapter(data, this.mContext);
        recyclerView.setAdapter(orderItemAdapter);

        orderItemAdapter.setOrderItemClickListener(new OrderItemAdapter.OnOrderRecyclerItemClickListener(){

            @Override
            public void onItemRecyclerItemClick(int position) {
                Log.e("testOrder","onRecyclerItemClick"+position);
            }
        });

        return view;
    }
}